<template>
  <view class="healthyDietCard app_healthyDietCard" @click="handleClick">
    <image :src="diet.thumb" mode="aspectFill"></image>
    <view class="healthyDietListRight">
      <view class="title">{{ diet.title }}</view>
      <view class="intro">{{ diet.intro ? diet.intro : '--' }}</view>
      <view>
        {{
          diet.updateTime
            ? dayjs(new Date()).format('YYYY-MM-DD') === dayjs(diet.updateTime).format('YYYY-MM-DD')
              ? dayjs(diet.updateTime).from(dayjs())
              : diet.updateTime
            : diet.createTime
            ? dayjs(new Date()).format('YYYY-MM-DD') === dayjs(diet.createTime).format('YYYY-MM-DD')
              ? dayjs(diet.createTime).from(dayjs())
              : diet.createTime
            : ''
        }}
      </view>
    </view>
  </view>
</template>

<script>
import dayjs from 'dayjs'
export default {
  props: {
    diet: {
      type: Object
    }
  },
  data() {
    return {
      dayjs: null
    }
  },
  methods: {
    fmtData(val) {
      return dayjs(val).from(dayjs())
    },
    handleClick() {
      this.$emit('HEALTHY_CARD_CLICK', this.diet)
    }
  },
  created() {
    this.dayjs = dayjs
  }
}
</script>

<style lang="scss">
app-healthy-card {
  display: block;
}
.healthyDietCard {
  width: 100%;
  height: 300rpx;
  background: #ffffff;
  box-shadow: 0px 10rpx 40rpx 0px rgba(0, 0, 0, 0.1);
  border-radius: 20rpx;
  display: flex;
  image {
    width: 240rpx;
    height: 300rpx;
    margin-right: 34rpx;
  }
  .healthyDietListRight {
    width: 390rpx;
    font-size: 24rpx;
    color: #999999;
    line-height: 40rpx;
    padding-top: 10rpx;
    .title {
      font-size: 30rpx;
      line-height: 64rpx;
      color: #000000;
      width: 380rpx;
      @include text-ellipsis;
    }
    .intro {
      height: 160rpx;
      margin-bottom: 10rpx;
      @include ellipsis4line($lineCount: 4);
    }
  }
}
</style>
